package face.pay.web.com.applyment.wx;

import face.pay.common.enterprise.service.IMchMediaBaseServcice;
import face.pay.entity.UserInfo;
import face.pay.entity.WeChatMchInfo;
import face.pay.system.annotation.CurrentUser;
import face.pay.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther: zkj
 * @Date: 2019/8/29 12:06
 * @Description:商户物料
 */
@RestController
@RequestMapping("/wxapply")
public class WxApplyMentEditController {

    @Autowired
    private IMchMediaBaseServcice iMchMediaServcice;


    /**
     * 物料上传
     * @param file
     * @param keyName
     * @param loginUser
     * @return
     * @throws Exception
     */
    @RequestMapping("/media_upload")
    public ResultMessage wxUpload(@RequestParam("file") MultipartFile file, WeChatMchInfo weChatMchInfo,
            String keyName, @CurrentUser UserInfo loginUser) throws  Exception{
        return  iMchMediaServcice.mediaload(weChatMchInfo,file.getBytes(),file.getOriginalFilename(),keyName,loginUser);
    }

    /**
     * 物料获取
     * @param request
     * @param response
     * @param mediaId
     * @param loginUser
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getMedia",produces = MediaType.IMAGE_JPEG_VALUE)
    public byte[]  getMedia(HttpServletRequest request, HttpServletResponse response,String mediaId,@CurrentUser UserInfo loginUser){
        return  iMchMediaServcice.getMedia(mediaId,loginUser);
    }


    /**
     * 进件提交
     * @param loginUser
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/subinfo")
    public ResultMessage  subinfo(WeChatMchInfo weChatMchInfo,@CurrentUser UserInfo loginUser) throws  Exception{
        return  iMchMediaServcice.subinfo(weChatMchInfo,loginUser);
    }








}
